<title>系统设置</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="home/info">主页</a>
        <a><cite>系统管理</cite></a>
        <a><cite>协议管理</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">协议管理</div>
        <div class="layui-card-body">
            <div class="layui-tab layui-tab-brief" lay-filter="system-protocol-tabs">
                <ul class="layui-tab-title">
                    <li class="layui-this">用户协议</li>
                    <li>隐私协议</li>

                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form" lay-filter="component-form-group">
                            <div class="layui-form-item">
                                <label class="layui-form-label">协议内容</label>
                                <div class="layui-input-block">
                                    <input hidden name="name" value="protocol">
                                    <input hidden name="key" value="user">
                                    <script type="text/html" template lay-url="/api/admin/system/setting/get" lay-data="{name: 'protocol'}" lay-done="layui.data.done(d,'user')">
                                    <textarea id="protocol-user" class="layui-input">{{ d.data.data.user || '' }}</textarea>
                                    </script>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline">
                                    <button class="layui-btn" lay-submit="" lay-filter="protocol-submit-user">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-tab-item">
                        <div class="layui-form" lay-filter="component-form-group">
                            <div class="layui-form-item">
                                <label class="layui-form-label">协议内容</label>
                                <div class="layui-input-block">
                                    <input hidden name="name" value="protocol">
                                    <input hidden name="key" value="privacy">
                                    <script type="text/html" template lay-url="/api/admin/system/setting/get" lay-data="{name: 'protocol'}" lay-done="layui.data.done(d,'privacy')">
                                        <textarea id="protocol-privacy" class="layui-input">{{ d.data.data.privacy || '' }}</textarea>
                                    </script>
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label"></label>
                                <div class="layui-input-inline">
                                    <button class="layui-btn" lay-submit="" lay-filter="protocol-submit-privacy">保存</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    layui.data.done = function (d,type){

        layui.use(['admin','tinymce'], function(){
            var $ = layui.$
                ,admin = layui.admin
                ,form = layui.form
                ,tinymce = layui.tinymce;


            tinymce.render({
                elem: "#protocol-"+type
                , height: 600
                , width:'100%'
            });

            //监听提交
            form.on('submit(protocol-submit-'+type+')', function (data) {
                var field = data.field; //获取提交的字段

                field.data = tinyMCE.editors['protocol-'+type].getContent();
                //提交 Ajax 成功后，关闭当前弹层并重载表格
                //$.ajax({});
                admin.req({
                    url: '/api/admin/system/value/save'
                    , data: data.field
                    , type: 'post'
                    , done: function (res) {
                        window.location.reload();
                    }
                });

                return false;
            });


        });
    }

</script>